*** REPLICATION FILE ***

*** Title: "Varieties of clientelism across political parties: new measures of patron–client relationships," 
*** Journal: European Political Science Review (2024), 16, 260–280
*** Authors: Masaaki Higashijima and Hidekuni Washida 
*** Stata (ver. 17) code written by Hidekuni Washida, 2023/03/30

*************************
**********VDEM**********
*************************

gen ccode=COWcode
drop if year<1950
sort ccode year
gen id=_n
order id ccode year 
drop if ccode==.

gen _v2elvotbuy = -v2elvotbuy
gen _v2dlencmps = -v2dlencmps
gen _v2psprlnks = -v2psprlnks

by ccode (year), sort: replace _v2elvotbuy = _v2elvotbuy[_n-1] if _v2elvotbuy >= . 
by ccode (year), sort: replace _v2dlencmps = _v2dlencmps[_n-1] if _v2dlencmps >= . 
by ccode (year), sort: replace _v2psprlnks = _v2psprlnks[_n-1] if _v2psprlnks >= . 
by ccode (year), sort: replace v2xnp_client = v2xnp_client[_n-1] if v2xnp_client >= . 

xtset ccode year
gen le_polity2=l.e_polity2
gen lv2xel_regelec=l.v2xel_regelec
gen le_gdppc=l.e_gdppc
gen le_lngdppc000=ln(le_gdppc*1000)
gen lgrowth=llne_gdppc000-l.llne_gdppc000


*************************
*********VPARTY*********
*************************
gen id=_n
gen ccode=COWcode
order id ccode year
* drop year==1965 (only one observation)
drop if year<1970
gen one=1
bysort v2paid (year) : gen t = sum( one )
drop one
xtset v2paid t

* merge v-dem
merge m:1 ccode year using "__________\V-Dem-CY-Full+Others-v12.dta" , keepusing(le_lngdppc000 lgrowth _v2elvotbuy _v2dlencmps _v2psprlnks v2xnp_client le_polity2  lv2xel_regelec)
gen ___VDEM___=.
drop _merge
drop if id==.

label var le_lngdppc000 "ln GDPpc (lag)"

* factor
fac v2paclient v2pasalie_11 v2palocoff  v2paactcom v2pafunds_5 v2pafunds_7, pcf
predict pc1b_relational pc2b_singleshot
scree
loadingplot, aspect(1) 
sum v2paclient v2pasalie_11 v2palocoff  v2paactcom v2pafunds_5 v2pafunds_7 if e(sample)==1

gen pc1b_relational01= (pc1b_relational+2.128805)/(2.128805 + 3.306974)
gen pc2b_singleshot01= ( pc2b_singleshot + 2.172682) / (2.172682 + 3.855179)

* correlation
corr pc1b_relational pc2b_singleshot _v2elvotbuy _v2dlencmps _v2psprlnks v2xnp_client if govD==1
corr pc1b_relational pc2b_singleshot _v2elvotbuy _v2dlencmps _v2psprlnks v2xnp_client if govD==0 

* region
label define regionlabel 1 "Eastern Europe & Central Asia" 2 "Latin America & the Caribbean" 3 "MENA" 4 "Sub-Saharan Africa" 5 "Western Europe & North America" 6 "Asia & Pacific"
label value e_regionpol_6C regionlabel

* creating weighted mean data
table e_regionpol_6C govop if year<1981 & govop!=1 [aweight=v2paseatshare], contents(mean pc2b_singleshot01 mean pc1b_relational01)
table e_regionpol_6C govop if year>1980 & year<1991 & govop!=1  [aweight=v2paseatshare], contents(mean pc2b_singleshot01 mean pc1b_relational01)
table e_regionpol_6C govop if year>1990 & year<2001 & govop!=1  [aweight=v2paseatshare], contents(mean pc2b_singleshot01 mean pc1b_relational01)
table e_regionpol_6C govop if year>2000 & year<2011 & govop!=1 [aweight=v2paseatshare], contents(mean pc2b_singleshot01 mean pc1b_relational01)
table e_regionpol_6C govop if year>2010 & govop!=1 [aweight=v2paseatshare], contents(mean pc2b_singleshot01 mean pc1b_relational01)

************************************

* government
gen govD=v2pagovsup<2 if  v2pagovsup!=4
gen govop=v2pagovsup
recode govop 0=3 1=2 2=1 3=0 4=.
gen govDL=govop==3 if v2pagovsup!=.
gen govDLch=govDL-l.govDL
gen govDLconsec=0
replace govDLconsec=1 if govDL==1 & l.govDL==1

* tenure
bysort v2paid (year) : gen cum_govD = sum( govD )
gen lncum_govD=ln(cum_govD+1)
gen cum_govDinc=cum_govD*govD
bysort v2paid (year) : gen cum_govDL = sum( govDL )
bysort v2paid (year) : gen cum_govDLconsec = sum( govDLconsec )

sort v2paid t
bysort v2paid (t) : gen govDLconsecy=(year-l.year )*govDLconsec
replace govDLconsecy=0 if govop!=3
bysort v2paid (t) : gen cum_govDLconsecy = sum( govDLconsecy ) if govDLconsec==1
replace cum_govDLconsecy=0 if govop!=3
gen lncum_govDL=ln(cum_govDL+1)
bysort v2paid (t) : gen cum_govDLconsecyb = sum( govDLconsecy ) if govDLconsec==1

gen lose_cum_govDL=cum_govDL if govDLch==-1
by v2paid (t), sort: replace lose_cum_govDL= lose_cum_govDL[_n-1] if lose_cum_govDL >= . 
gen cum_govDLnc=cum_govDL
replace cum_govDLnc = cum_govDLnc - lose_cum_govDL if lose_cum_govDL!=.
replace cum_govDLnc=. if govop==.
gen cum_govDLnc5 = cum_govDLnc
recode cum_govDLnc5 11=5 10=5 9=5 8=5 7=5 6=5
label define cum5 1 "1" 2 "2" 3 "3" 4 "4" 5 "4<"
label value cum_govDLnc5 cum5

* regelec
gen lv2xel_regelecD=0 if  lv2xel_regelec<.487 & lv2xel_regelec!=.
recode lv2xel_regelecD .=1 if  lv2xel_regelec>=.487 & lv2xel_regelec!=.

*********************************
************TABLE****************
*********************************

*** relational
* linear
xtmixed pc1b_relational01 c.govop c.le_lngdppc000 c.le_lngdppc000 le_polity2 lv2xel_regelecD  lgrowth  i.year i.e_regionpol_6C || COWcode: ||v2paid:
estimates store m1
estat ic
* curvilinear
xtmixed pc1b_relational01 c.govop c.le_lngdppc000##c.le_lngdppc000 le_polity2 lv2xel_regelecD  lgrowth  i.year i.e_regionpol_6C || COWcode: ||v2paid:
estimates store m2
estat ic
* gov*development
xtmixed pc1b_relational01 c.govop##c.le_lngdppc000##c.le_lngdppc000 le_polity2 lv2xel_regelecD  lgrowth  i.year i.e_regionpol_6C || COWcode: ||v2paid:
estimates store m3
estat ic
* tenure
xtmixed pc1b_relational01 c.govop##c.le_lngdppc000##c.le_lngdppc000  c.cum_govDLnc5##c.cum_govDLnc5 le_polity2 lv2xel_regelecD   lgrowth  i.year i.e_regionpol_6C || COWcode: ||v2paid:
estimates store m4
estat ic

* region
xtmixed pc1b_relational01 c.govop##c.le_lngdppc000##c.le_lngdppc000##c.lv2xel_regelecD le_polity2  lgrowth  i.year i.e_regionpol_6C || COWcode: ||v2paid:
estimates store m5
estat ic

esttab m1 m2 m3 m4 m5 using table1.tex, se r2 star("\dag" 0.10 * 0.05 ** 0.01 *** 0.001) replace

*** singleshot
* linear
xtmixed pc2b_singleshot01  c.govop c.le_lngdppc000 c.le_lngdppc000 le_polity2 lv2xel_regelecD  lgrowth  i.year i.e_regionpol_6C || COWcode: ||v2paid:
estimates store m1
estat ic
* curvilinear
xtmixed pc2b_singleshot01  c.govop c.le_lngdppc000##c.le_lngdppc000 le_polity2 lv2xel_regelecD  lgrowth  i.year i.e_regionpol_6C || COWcode: ||v2paid:
estimates store m2
estat ic
* gov*development
xtmixed pc2b_singleshot01  c.govop##c.le_lngdppc000##c.le_lngdppc000 le_polity2 lv2xel_regelecD  lgrowth  i.year i.e_regionpol_6C || COWcode: ||v2paid:
estimates store m3
estat ic
* tenure
xtmixed pc2b_singleshot01  c.govop##c.le_lngdppc000##c.le_lngdppc000  c.cum_govDLnc5##c.cum_govDLnc5 le_polity2 lv2xel_regelecD   lgrowth  i.year i.e_regionpol_6C || COWcode: ||v2paid:
estimates store m4
estat ic

* region
xtmixed pc2b_singleshot01  c.govop##c.le_lngdppc000##c.le_lngdppc000##c.lv2xel_regelecD le_polity2  lgrowth  i.year i.e_regionpol_6C || COWcode: ||v2paid:
estimates store m5
estat ic

esttab m1 m2 m3 m4 m5 using table2.tex, se r2 star("\dag" 0.10 * 0.05 ** 0.01 *** 0.001)  replace


*********************************
************FIGURE***************
*********************************

* base: relational
xtmixed pc1b_relational01 c.govop c.le_lngdppc000##c.le_lngdppc000 le_polity2 lv2xel_regelecD  lgrowth  i.year i.e_regionpol_6C || COWcode: ||v2paid:
margins,  at(le_lngdppc000=(5.7(.7)11.4))  
qui marginsplot, title("Relational & development") ytitle("") xlabel(6(1)11)  recast(line) recastci(rarea) ciopt(color(%40)) addplot(hist le_lngdppc000,  bcolor(gs10) bfcolor(none)  yaxis (2) percent yscale(alt lcolor() axis (2)) ytitle("", axis (2)) bin(11) ) legend(off) saving(base1a, replace)

* base: single
xtmixed pc2b_singleshot01 c.govop c.le_lngdppc000##c.le_lngdppc000 le_polity2 lv2xel_regelecD  lgrowth  i.year i.e_regionpol_6C || COWcode: ||v2paid:
margins,  at(le_lngdppc000=(5.7(.7)11.4))  
qui marginsplot, title("Single-shot & development") ytitle("") xlabel(6(1)11)  recast(line) recastci(rarea) ciopt(color(%40)) addplot(hist le_lngdppc000,  bcolor(gs10) bfcolor(none)  yaxis (2) percent yscale(alt lcolor() axis (2)) ytitle("", axis (2)) bin(11) ) legend(off) saving(base2a, replace)

graph combine base1a.gph base2a.gph , cols(2) saving(_RnR_Fig_base, replace)

***
* by govop: relational
xtmixed pc1b_relational01 c.govop##c.le_lngdppc000##c.le_lngdppc000  le_polity2 lv2xel_regelecD  lgrowth  i.year i.e_regionpol_6C || COWcode: ||v2paid:
margins,  at(govop=2 le_lngdppc000=(5.7(.7)11.4))  saving(R1a, replace)
margins,  at(govop=0 le_lngdppc000=(5.7(.7)11.4))  saving(R1c, replace)
combomarginsplot R1a  R1c, title("Relational & development") ytitle("")  xlabel(6(1)11) recast(line) recastci(rarea) ciopt(color(%40)) addplot(hist le_lngdppc000,  bcolor(gs10) bfcolor(none)  yaxis (2) percent yscale(alt lcolor() axis (2)) ytitle("", axis (2)) bin(11) ) legend(off) saving(base1b, replace)

* by govop: single-shot
xtmixed pc2b_singleshot01 c.govop##c.le_lngdppc000##c.le_lngdppc000 le_polity2  lv2xel_regelecD lgrowth  i.year i.e_regionpol_6C || COWcode: ||v2paid:
margins,  at(govop=2 le_lngdppc000=(5.7(.7)11.4))  saving(S1a, replace)
margins,  at(govop=0 le_lngdppc000=(5.7(.7)11.4))  saving(S1c, replace)
combomarginsplot S1a  S1c, title("Single-shot & development") ytitle("")  xlabel(6(1)11) recast(line) recastci(rarea) ciopt(color(%40))  addplot(hist le_lngdppc000,  bcolor(gs10) bfcolor(none)  yaxis (2) percent yscale(alt lcolor() axis (2)) ytitle("", axis (2)) bin(11) ) legend(off) saving(base2b, replace)

graph combine base1b.gph base2b.gph , cols(2) saving(_RnR_Fig_bygov, replace)

* tenure5: relational
xtmixed pc1b_relational01 c.govop##c.le_lngdppc000##c.le_lngdppc000  c.cum_govDLnc5##c.cum_govDLnc5 le_polity2 lv2xel_regelecD   lgrowth  i.year i.e_regionpol_6C || COWcode: ||v2paid:
margins,  at(cum_govDLnc5=(0(1)5))  
qui marginsplot, title("Relational & Tenure") ytitle("") recast(line) recastci(rarea) ciopt(color(%40)) addplot(hist cum_govDLnc5,  bcolor(gs10) bfcolor(none)  yaxis (2) percent yscale(alt lcolor() axis (2)) ytitle("", axis (2)) bin(5) ) legend(off)  saving(tenure1, replace)

* tenure5: single-shot
xtmixed pc2b_singleshot01 c.govop##c.le_lngdppc000##c.le_lngdppc000  c.cum_govDLnc5##c.cum_govDLnc5 le_polity2 lv2xel_regelecD  lgrowth  i.year i.e_regionpol_6C || COWcode: ||v2paid:
margins,  at(cum_govDLnc5=(0(1)5)) 
qui marginsplot,  title("Single-shot & Tenure") ytitle("") recast(line) recastci(rarea) ciopt(color(%40)) addplot(hist cum_govDLnc5,  bcolor(gs10) bfcolor(none)  yaxis (2) percent yscale(alt lcolor() axis (2))   ytitle("", axis (2)) bin(5) ) legend(off)  saving(tenure2, replace)

graph combine tenure1.gph tenure2.gph, cols(2) saving(_RnR_Fig_tenure, replace)

* by govop X region: relational

xtmixed pc1b_relational01 c.govop##c.le_lngdppc000##c.le_lngdppc000##c.lv2xel_regelecD le_polity2  lgrowth  i.year i.e_regionpol_6C || COWcode: ||v2paid:
margins,  at(govop=2 le_lngdppc000=(5.7(.7)11.4) lv2xel_regelecD =(0))  saving(R1a, replace)
margins,  at(govop=0 le_lngdppc000=(5.7(.7)11.4) lv2xel_regelecD =(0))  saving(R1b, replace)
combomarginsplot R1a R1b, title("Relational & centralized") ytitle("") xlabel(6(1)11) recast(line) recastci(rarea) ciopt(color(%40)) addplot(hist le_lngdppc000cent,  bcolor(gs10) bfcolor(none)  yaxis (2) percent yscale(alt lcolor() axis (2)) ytitle("", axis (2)) bin(11) ) legend(off) saving(region1a, replace)
margins,  at(govop=2 le_lngdppc000=(6.5(.5)11) lv2xel_regelecD =( 1))  saving(R1c, replace)
margins,  at(govop=0 le_lngdppc000=(6.5(.5)11) lv2xel_regelecD =( 1))  saving(R1d, replace)
combomarginsplot R1c R1d, title("Relational & decentralized") ytitle("") xlabel(6.5(.5)11) recast(line) recastci(rarea) ciopt(color(%40)) addplot(hist le_lngdppc000decent ,  bcolor(gs10) bfcolor(none)  yaxis (2) percent yscale(alt lcolor() axis (2)) ytitle("", axis (2)) bin(9) ) legend(off) saving(region1b, replace)
* by govop X region: single-shot
xtmixed pc2b_singleshot01 c.govop##c.le_lngdppc000##c.le_lngdppc000##c.lv2xel_regelecD  le_polity2 lgrowth  i.year i.e_regionpol_6C || COWcode: ||v2paid:
margins,  at(govop=2 le_lngdppc000=(5.7(.7)11.4) lv2xel_regelecD =(0))  saving(S1a, replace)
margins,  at(govop=0 le_lngdppc000=(5.7(.7)11.4) lv2xel_regelecD =(0))  saving(S1c, replace)
combomarginsplot S1a S1c, title("Single-shot & centralized") ytitle("") xlabel(6(1)11) recast(line) recastci(rarea) ciopt(color(%40))  addplot(hist le_lngdppc000cent,  bcolor(gs10) bfcolor(none)  yaxis (2) percent yscale(alt lcolor() axis (2)) ytitle("", axis (2)) bin(11) ) legend(off) saving(region2a, replace)
margins,  at(govop=2 le_lngdppc000=(6.5(.5)11) lv2xel_regelecD =(1))  saving(S1a, replace)
margins,  at(govop=0 le_lngdppc000=(6.5(.5)11) lv2xel_regelecD =(1))  saving(S1c, replace)
combomarginsplot S1a S1c, title("Single-shot & decentralized") ytitle("") xlabel(6.5(.5)11) recast(line) recastci(rarea) ciopt(color(%40))  addplot(hist le_lngdppc000decent,  bcolor(gs10) bfcolor(none)  yaxis (2) percent yscale(alt lcolor() axis (2)) ytitle("", axis (2)) bin(9) ) legend(off) saving(region2b, replace)

graph combine region1a.gph region1b.gph region2a.gph region2b.gph, cols(2) saving(_RnR_Fig_region, replace)

* descriptive
qui xtmixed pc1b_relational01 c.govop c.le_lngdppc000##c.le_lngdppc000 le_polity2 lv2xel_regelecD  lgrowth  i.year i.e_regionpol_6C || COWcode: ||v2paid:
sum pc1b_relational01 pc2b_singleshot01 govop le_lngdppc000 le_polity2 lv2xel_regelecD lgrowth cum_govDLnc5 if e(sample)==1
